﻿using System;

namespace YXYLCommon
{
    [Serializable]
    public class BasePageInfo
    {
        public BasePageInfo()
        {
            this.PageIndex = 1;
            this.PageSize = 100;
        }

        public DbProcObject dbProcObject { get; set; }

        public int PageIndex { get; set; }

        public int PageSize { get; set; }

        public int StartNo
        {
            get
            {
                return (PageIndex - 1) * PageSize + 1;
            }
        }

        public int EndNo
        {
            get
            {
                return PageIndex * PageSize;
            }
        }

        public int RecordsCount { get; set; }

        public int PagesCount
        {
            get
            {
                return RecordsCount % PageSize == 0 ? RecordsCount / PageSize : RecordsCount / PageSize+1;
            }
        }

        /// <summary>
        /// 填充分页信息
        /// </summary>
        public void FillPageInfo(DbProcObject procOject)
        {
            procOject.ProcParameters.Clear();
            procOject.AddParameter("@StartNo",this.StartNo);
            procOject.AddParameter("@EndNo", this.EndNo);
            procOject.AddParameterOut("@RecordsCount", this.RecordsCount,4);
            this.FillCondition(procOject);
            this.dbProcObject = procOject;
        }

        /// <summary>
        /// 填充分页条件(子类重写)
        /// </summary>
        /// <param name="procOject"></param>
        protected virtual void FillCondition(DbProcObject procOject)
        { 
        
        }
    }
}
